Passed
Pull Request — master (#92)
by Mark
01:32
created

ConnectionSettings.getBaseUrl   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
/**
2
 *
3
 */
4
export default class ConnectionSettings {
5
6
    private baseUrl: string;
7
8
    private cache: string;
9
10
    private contentType: string;
11
12
    private headers: object;
13
14
    private mode: string;
15
16
    /**
17
     *
18
     */
19
    constructor() {
20
        this.contentType = 'application/json';
21
        this.mode = 'cors';
22
        this.cache = 'no-cache';
23
        this.headers = {};
24
        this.baseUrl = 'http://localhost';
25
    }
26
27
    getBaseUrl(): string {
28
        return this.baseUrl;
29
    }
30
31
    getSettings(): object {
32
        return {
33
            "mode": this.mode, // no-cors, *cors, same-origin
34
            "cache": this.cache, // *default, no-cache, reload, force-cache, only-if-cached
35
            //credentials: 'same-origin', // include, *same-origin, omit
36
            "headers": {
37
                'Accept': this.contentType,
38
                'Content-Type': this.contentType,
39
                ...this.headers
40
            },
41
            "redirect": 'follow', // manual, *follow, error
42
            "referrerPolicy": 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
43
        };
44
    }
45
46
    setBaseUrl(baseUrl: string): ConnectionSettings {
47
        this.baseUrl = baseUrl ?? 'http://localhost';
48
        return this;
49
    }
50
}
51